/*
 * MisMain.java
 *
 * Created on 27 de noviembre de 2006, 03:04 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package pruebas;

import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JFrame;

public class MisMain {

    public static void main(String[] arg) throws Exception {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@200.1.82.6:1621:metricap", "metricadb", "metricadb");

        String query = ("SELECT POSICION, VALOR FROM METRICADW..VALORESMATRICES WHERE IDMATRIZ = 3 ORDER BY POSICION ");

        String DATA_BASE = connection.getMetaData().getDatabaseProductName().trim();
        String user = connection.getCatalog();
        String Mdw="METRICADW";
        String Mdb="METRICADB";
        if (user == null && DATA_BASE.trim().equals("Oracle")) {
            user = connection.getMetaData().getUserName();
        }

        if (user.equalsIgnoreCase("METRICADW")) {
            Mdw = connection.getCatalog();
            if (Mdw == null && DATA_BASE.trim().equals("Oracle")) {
                Mdw = connection.getMetaData().getUserName();
            }
        } else if (user.equalsIgnoreCase("METRICADB")) {
            Mdb = connection.getCatalog();
            if (Mdb == null && DATA_BASE.trim().equals("Oracle")) {
                Mdb = connection.getMetaData().getUserName();
            }
        }

        query = query.toUpperCase();
        //se hace el cambio de los nombres quemados de metricadb y metricadw

        String VACIO = "";
        if (DATA_BASE.equals("Oracle")) {
            VACIO = ".";
            query = query.replace("ISNULL", "NVL");
        }

        query = query.replace("METRICADB" + VACIO, Mdb);
        query = query.replace("METRICADW" + VACIO, Mdw);
        System.out.println("query : "+query);
    }
}
